package com.zhiqianbao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhiqianbao.R;
import com.zhiqianbao.entity.PhoneContact;

import java.util.List;

/**
 * Created by 亮 on 2015/12/27.
 */
public class PhoneContactListAdapter extends BaseAdapter{
    private LayoutInflater inflater;
    private List<PhoneContact> list;
    private String[] sections;
    private Context ctx;

    private final class ListItemView {
        public TextView name;
        public TextView num;
    }

    public PhoneContactListAdapter(Context context, List<PhoneContact> list) {
        this.ctx = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ListItemView listItemView = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.list_item_contacts_mobile, null);
            listItemView = new ListItemView();
            listItemView.name = (TextView) convertView.findViewById(R.id.name);
            listItemView.num = (TextView) convertView.findViewById(R.id.number);
            convertView.setTag(listItemView);
        } else {
            listItemView = (ListItemView) convertView.getTag();
        }

        String name = list.get(position).getDesplayName();
        String num = list.get(position).getPhoneNum();

        listItemView.name.setText(name);
        listItemView.num.setText(num);
        return convertView;
    }
}
